package org.spring.aicloud.util;

import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 统一的异常处理类
 */
@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(BindException.class)
    public ResponseEntity handleException(BindException e){
        return ResponseEntity.fail(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }
    @ExceptionHandler(Exception.class)
    public ResponseEntity handleException(Exception e){
        return ResponseEntity.fail(e.getMessage());
    }

}
